<{include file="public/header.html"}> 
	<header class="title title-border-sm bj-white">
		<a href="javascript:history.go(-1);" class="icon-return iconfont title-left title-top col-red">&#xe604;</a>
		<h1 class="text-center name">找回密码</h1>
	</header>
	<form class="plr10" id="form-check" action="" data-href="" onsubmit="return false;">
		<div class="input-group input-group-70">
			<input type="text" name="uMobile" id="uMobile" placeholder="请输入11位手机号码" oninput="if(value.length>11)value=value.slice(0,11)" data-validate="mobile" data-describedby="mobile-description"/>
		</div>
		<div class="input-group input-group-70">
			<input type="text" name="uCode" id="uCode" maxlength="6" placeholder="输入短信验证码" oninput="if(value.length>6)value=value.slice(0,6)" data-validate="code" data-describedby="code-description"/>
                        <a href="javascript:void(0);" class="send-code fr col-red bj-grey" id="send-code-btn">发送验证码</a>
		</div>
		
		<!--里面的A标签到时候是要删掉的-->
                <input type="submit" class="btn btn-yes mt10" value="验证手机" id="form-check-btn"/>
	</form>
<script type="text/javascript">
var send_flag = true;
$(function(){
    var check_flag = true,check_count = 0;
    $.mvalidateExtend({
        //验证手机号 密码  校验码
        mobile:{
            required : true,   
            pattern : /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-3,5-9]{1})|(17[0,1,3,5-8]{1})|(18[0-9]{1}))+\d{8})$/,
            each:function(){

            },
            descriptions:{
                required : '<div class="field-invalidmsg">请填写手机号</div>',
                pattern : '<div class="field-invalidmsg">请填写您的真实手机号码</div>',
            }
        },
        code:{
            required : true,   
            pattern : /\b\d{6}\b/,
            each:function(){

            },
            descriptions:{
                required : '<div class="field-invalidmsg">请填写手机验证码</div>',
                pattern : '<div class="field-invalidmsg">请填写有效的验证码</div>',
            }
        }
    });
     $("#form-check").mvalidate({
        type:1,
        onKeyup:true,
        sendForm:true,
        firstInvalidFocus:false,
        descriptions: {
        },
        valid:function(event,options){
            add_check_oper_listener();
            var url = $('#form-check').attr("data-href");
            check_flag = false;
            $("#form-check-btn").val("验证中...");
            $.ajax({
                type: "POST",
                url: url,
                async:true, 
                data: 'uCode=' + $('#uCode').val()+ '&uMobile=' + $('#uMobile').val(),
                success: function(resp) {
                    resp = $.parseJSON(resp);
                    if(resp.reqStatus){
                        window.location.href = resp.url;
                    }else{
                        cancel_check_oper_listener();
                        $("#form-check-btn").val("重新验证");
                        $.mvalidateTip(resp.errorMsg);
                        return false;
                    }
                }
            });
        },
        invalid:function(event, status, options){
            //点击提交按钮时,表单未通过验证触发函数
        },
        eachField:function(event,status,options){
            //点击提交按钮时,表单每个输入域触发这个函数 this 执向当前表单输入域，是jquery对象
        },
        eachValidField:function(val){},
        eachInvalidField:function(event, status, options){},
    })
    
    function add_check_oper_listener(){
        if(check_count == 2){
            check_count = 0;
            $.mvalidateTip("操作过于频繁");return false;
        }
        if(!check_flag){
            check_count ++;
            $.mvalidateTip("正在处理验证操作");return false;
        }
    };
    function cancel_check_oper_listener(){
        check_count = 0;
        check_flag = true;
    }
    
    var total_time = 60;
    var isMobile = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-3,5-9]{1})|(17[0,1,3,5-8]{1})|(18[0-9]{1}))+\d{8})$/;
    
    $("#send-code-btn").on("click",function(){
        var _self = $(this);
        if(!send_flag){
            $.mvalidateTip("操作过于频繁");return;
        }
        
        var start_time = function(){
            for (var i = 1; i <= total_time; i++) {
                window.setTimeout("update_p("+ i + "," + total_time + ")", i * 1000);
            }
        }
        var send = function(){
            var mobile = $("#uMobile").val();
            if(mobile == ""){
                $.mvalidateTip("请输入手机号");return;
            }
            if(!isMobile.test(mobile)){
                $.mvalidateTip("手机格式不正确");return;
            }
            send_flag = false;
            $.ajax({
                type: "POST",
                url: "/ajax/send_findpwd_code",
                async:true, 
                data: 'uMobile=' + mobile,
                success: function(resp) {
                    resp = $.parseJSON(resp);
                    if(resp.reqStatus){
                        $.mvalidateTip("验证码已发送");
                        return start_time();
                    }else{
                        send_flag = true;
                        $.mvalidateTip(resp.errorMsg);
                        return;
                    }
                }
            });
        }
        send();
    });
});
var update_p = function(num,t){
    if (num == t) {
        $("#send-code-btn").text("重新获取").addClass("col-red").removeClass("col-grey999");
        send_flag = true;
    } else {
        var printnr = t - num;
        $("#send-code-btn").text("剩余"+printnr + "秒").removeClass("col-red").addClass("col-grey999");
    }
}
</script>
<{include file="public/footer.html"}> 